home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 1 / Meeting Pearls Vol 1 (1994).iso / installed_progs / text / faqs / compression-faq.part2 < prev    next >
Encoding:
Internet Message Format  |  1994-04-18  |  85.8 KB

  1. Subject: comp.compression Frequently Asked Questions (part 2/3)
  2. Newsgroups: comp.compression,comp.compression.research,news.answers,comp.answers
  3. From: jloup@chorus.fr (Jean-loup Gailly)
  4. Date: 17 Apr 94 12:28:51 GMT
  5.  
  6. Archive-name: compression-faq/part2
  7. Last-modified: April 17th, 1994
  8.  
  9. This file is part 2 of a set of Frequently Asked Questions for the
  10. groups comp.compression and comp.compression.research.
  11. If you did not get part 1 or 3, you can get them by ftp
  12. on rtfm.mit.edu in directory
  13.    /pub/usenet/news.answers/compression-faq
  14.  
  15. If you don't want to see this FAQ regularly, please add the subject
  16. line to your kill file. If you have corrections or suggestions for
  17. this FAQ, send them to Jean-loup Gailly <jloup@chorus.fr>.  Thank you.
  18.  
  19. Contents
  20. ========
  21.  
  22. Part 2: (Long) introductions to data compression techniques
  23.  
  24. [70] Introduction to data compression (long)
  25.        Huffman and Related Compression Techniques
  26.        Arithmetic Coding
  27.        Substitutional Compressors
  28.           The LZ78 family of compressors
  29.           The LZ77 family of compressors
  30.  
  31. [71] Introduction to MPEG (long)
  32.        What is MPEG?
  33.        Does it have anything to do with JPEG?
  34.        Then what's JBIG and MHEG?
  35.        What has MPEG accomplished?
  36.        So how does MPEG I work?
  37.        What about the audio compression?
  38.        So how much does it compress?
  39.        What's phase II?
  40.        When will all this be finished?
  41.        How do I join MPEG?
  42.        How do I get the documents, like the MPEG I draft?
  43.  
  44. [72] What is wavelet theory?
  45. [73] What is the theoretical compression limit?
  46. [74] Introduction to JBIG
  47. [75] Introduction to JPEG
  48. [76] What is Vector Quantization?
  49. [77] Introduction to Fractal compression
  50.  
  51. Part 3: (Long) list of image compression hardware
  52.  
  53. [85] Image compression hardware
  54. [99] Acknowledgments
  55.  
  56.  
  57. Search for "Subject: [#]" to get to question number # quickly. Some news
  58. readers can also take advantage of the message digest format used here.
  59.  
  60. ------------------------------------------------------------------------------
  61.  
  62. Subject: [70] Introduction to data compression (long)
  63.  
  64.  
  65. Written by Peter Gutmann <pgut1@cs.aukuni.ac.nz>.
  66.  
  67.  Huffman and Related Compression Techniques
  68.  ------------------------------------------
  69.  
  70.   *Huffman compression* is a statistical data compression technique which 
  71. gives a reduction in the average code length used to represent the symbols of 
  72. a alphabet.  The Huffman code is an example of a code which is optimal in the 
  73. case where all symbols probabilities are integral powers of 1/2.  A Huffman 
  74. code can be built in the following manner:
  75.  
  76.   (1) Rank all symbols in order of probability of occurrence.
  77.     
  78.   (2) Successively combine the two symbols of the lowest probability to form
  79.       a new composite symbol; eventually we will build a binary tree where
  80.       each node is the probability of all nodes beneath it.
  81.  
  82.   (3) Trace a path to each leaf, noticing the direction at each node.
  83.  
  84.   For a given frequency distribution, there are many possible Huffman codes,
  85. but the total compressed length will be the same. It is possible to
  86. define a 'canonical' Huffman tree, that is, pick one of these alternative
  87. trees. Such a canonical tree can then be represented very compactly, by
  88. transmitting only the bit length of each code. This technique is used
  89. in most archivers (pkzip, lha, zoo, arj, ...).
  90.  
  91.  
  92.   A technique related to Huffman coding is *Shannon-Fano coding*, which
  93. works as follows:
  94.  
  95.   (1) Divide the set of symbols into two equal or almost equal subsets
  96.       based on the probability of occurrence of characters in each
  97.       subset.  The first subset is assigned a binary zero, the second
  98.       a binary one.
  99.  
  100.   (2) Repeat step (1) until all subsets have a single element.
  101.  
  102. The algorithm used to create the Huffman codes is bottom-up, and the
  103. one for the Shannon-Fano codes is top-down. Huffman encoding always
  104. generates optimal codes, Shannon-Fano sometimes uses a few more bits.
  105.  
  106.  
  107.  Arithmetic Coding
  108.  -----------------
  109.  
  110.   It would appear that Huffman or Shannon-Fano coding is the perfect
  111. means of compressing data.  However, this is *not* the case.  As
  112. mentioned above, these coding methods are optimal when and only when
  113. the symbol probabilities are integral powers of 1/2, which is usually
  114. not the case.
  115.  
  116.   The technique of *arithmetic coding* does not have this restriction:
  117. It achieves the same effect as treating the message as one single unit
  118. (a technique which would, for Huffman coding, require enumeration of
  119. every single possible message), and thus attains the theoretical
  120. entropy bound to compression efficiency for any source.
  121.  
  122.   Arithmetic coding works by representing a number by an interval of real 
  123. numbers between 0 and 1.  As the message becomes longer, the interval needed 
  124. to represent it becomes smaller and smaller, and the number of bits needed to 
  125. specify that interval increases.  Successive symbols in the message reduce 
  126. this interval in accordance with the probability of that symbol. The more
  127. likely symbols reduce the range by less, and thus add fewer bits to the   
  128. message.
  129.  
  130.      1                                             Codewords
  131.     +-----------+-----------+-----------+           /-----\
  132.     |           |8/9 YY     |  Detail   |<- 31/32    .11111
  133.     |           +-----------+-----------+<- 15/16    .1111
  134.     |    Y      |           | too small |<- 14/16    .1110
  135.     |2/3        |    YX     | for text  |<- 6/8      .110
  136.     +-----------+-----------+-----------+
  137.     |           |           |16/27 XYY  |<- 10/16    .1010
  138.     |           |           +-----------+
  139.     |           |    XY     |           |
  140.     |           |           |   XYX     |<- 4/8      .100
  141.     |           |4/9        |           |
  142.     |           +-----------+-----------+
  143.     |           |           |           |
  144.     |    X      |           |   XXY     |<- 3/8      .011
  145.     |           |           |8/27       |
  146.     |           |           +-----------+
  147.     |           |    XX     |           |
  148.     |           |           |           |<- 1/4      .01
  149.     |           |           |   XXX     |
  150.     |           |           |           |
  151.     |0          |           |           |
  152.     +-----------+-----------+-----------+
  153.  
  154.   As an example of arithmetic coding, lets consider the example of two
  155. symbols X and Y, of probabilities 0.66 and 0.33. To encode this message, we
  156. examine the first symbol: If it is a X, we choose the lower partition; if
  157. it is a Y, we choose the upper partition.  Continuing in this manner for
  158. three symbols, we get the codewords shown to the right of the diagram above
  159. - they can be found by simply taking an appropriate location in the
  160. interval for that particular set of symbols and turning it into a binary
  161. fraction. In practice, it is also necessary to add a special end-of-data
  162. symbol, which is not represented in this simpe example.
  163.         
  164.   In this case the arithmetic code is not completely efficient, which is due 
  165. to the shortness of the message - with longer messages the coding efficiency 
  166. does indeed approach 100%.
  167.  
  168.   Now that we have an efficient encoding technique, what can we do with it? 
  169. What we need is a technique for building a model of the data which we can 
  170. then use with the encoder.  The simplest model is a fixed one, for example a 
  171. table of standard letter frequencies for English text which we can then use 
  172. to get letter probabilities.  An improvement on this technique is to use an 
  173. *adaptive model*, in other words a model which adjusts itself to the data 
  174. which is being compressed as the data is compressed.  We can convert the 
  175. fixed model into an adaptive one by adjusting the symbol frequencies after 
  176. each new symbol is encoded, allowing the model to track the data being 
  177. transmitted.  However, we can do much better than that.
  178.  
  179. Using the symbol probabilities by themselves is not a particularly good
  180. estimate of the true entropy of the data: We can take into account
  181. intersymbol probabilities as well.  The best compressors available today
  182. take this approach: DMC (Dynamic Markov Coding) starts with a zero-order
  183. Markov model and gradually extends this initial model as compression
  184. progresses; PPM (Prediction by Partial Matching) looks for a match of the
  185. text to be compressed in an order-n context.  If no match is found, it
  186. drops to an order n-1 context, until it reaches order 0.  Both these
  187. techniques thus obtain a much better model of the data to be compressed,
  188. which, combined with the use of arithmetic coding, results in superior
  189. compression performance.
  190.  
  191.   So if arithmetic coding-based compressors are so powerful, why are they not 
  192. used universally?  Apart from the fact that they are relatively new and 
  193. haven't come into general use too much yet, there is also one major concern:  
  194. The fact that they consume rather large amounts of computing resources, both 
  195. in terms of CPU power and memory.  The building of sophisticated models for 
  196. the compression can chew through a fair amount of memory (especially in the 
  197. case of DMC, where the model can grow without bounds); and the arithmetic 
  198. coding itself involves a fair amount of number crunching.
  199. There is however an alternative approach, a class of compressors generally 
  200. referred to as *substitutional* or *dictionary-based compressors*.
  201.  
  202.  Substitutional Compressors
  203.  --------------------------
  204.  
  205.   The basic idea behind a substitutional compressor is to replace an 
  206. occurrence of a particular phrase or group of bytes in a piece of data with a 
  207. reference to a previous occurrence of that phrase.  There are two main 
  208. classes of schemes, named after Jakob Ziv and Abraham Lempel, who first 
  209. proposed them in 1977 and 1978.
  210.  
  211. <The LZ78 family of compressors>
  212.  
  213.   LZ78-based schemes work by entering phrases into a *dictionary* and then, 
  214. when a repeat occurrence of that particular phrase is found, outputting the 
  215. dictionary index instead of the phrase.  There exist several compression 
  216. algorithms based on this principle, differing mainly in the manner in which 
  217. they manage the dictionary.  The most well-known scheme (in fact the most 
  218. well-known of all the Lempel-Ziv compressors, the one which is generally (and 
  219. mistakenly) referred to as "Lempel-Ziv Compression"), is Terry Welch's LZW 
  220. scheme, which he designed in 1984 for implementation in hardware for high- 
  221. performance disk controllers.
  222.  
  223. Input string: /WED/WE/WEE/WEB
  224.  
  225. Character input:    Code output:    New code value and associated string:
  226.     /W                  /                   256 = /W
  227.     E                   W                   257 = WE
  228.     D                   E                   258 = ED
  229.     /                   D                   259 = D/
  230.     WE                  256                 260 = /WE
  231.     /                   E                   261 = E/
  232.     WEE                 260                 262 = /WEE
  233.     /W                  261                 263 = E/W
  234.     EB                  257                 264 = WEB
  235.     <END>               B
  236.     
  237.   LZW starts with a 4K dictionary, of which entries 0-255 refer to individual 
  238. bytes, and entries 256-4095 refer to substrings.  Each time a new code is 
  239. generated it means a new string has been parsed.  New strings are generated 
  240. by appending the current character K to the end of an existing string w.  The 
  241. algorithm for LZW compression is as follows:
  242.  
  243.   set w = NIL
  244.   loop
  245.       read a character K
  246.       if wK exists is in the dictionary
  247.           w = wK
  248.       else
  249.           output the code for w
  250.           add wK to the string table
  251.           w = K
  252.   endloop
  253.  
  254.   A sample run of LZW over a (highly redundant) input string can be seen in 
  255. the diagram above.  The strings are built up character-by-character starting 
  256. with a code value of 256.  LZW decompression takes the stream of codes and 
  257. uses it to exactly recreate the original input data.  Just like the 
  258. compression algorithm, the decompressor adds a new string to the dictionary 
  259. each time it reads in a new code.  All it needs to do in addition is to 
  260. translate each incoming code into a string and send it to the output.  A 
  261. sample run of the LZW decompressor is shown in below.
  262.  
  263. Input code: /WED<256>E<260><261><257>B
  264.  
  265. Input code:        Output string:     New code value and associated string:
  266.     /                  /            
  267.     W                  W                      256 = /W
  268.     E                  E                      257 = WE
  269.     D                  D                      258 = ED
  270.     256                /W                     259 = D/
  271.     E                  E                      260 = /WE
  272.     260                /WE                    261 = E/
  273.     261                E/                     262 = /WEE
  274.     257                WE                     263 = E/W
  275.     B                  B                      264 = WEB
  276.            
  277.   The most remarkable feature of this type of compression is that the entire 
  278. dictionary has been transmitted to the decoder without actually explicitly 
  279. transmitting the dictionary.  At the end of the run, the decoder will have a 
  280. dictionary identical to the one the encoder has, built up entirely as part of 
  281. the decoding process.
  282.     LZW is more commonly encountered today in a variant known as LZC, after 
  283. its use in the UNIX "compress" program.  In this variant, pointers do not 
  284. have a fixed length.  Rather, they start with a length of 9 bits, and then 
  285. slowly grow to their maximum possible length once all the pointers of a 
  286. particular size have been used up.  Furthermore, the dictionary is not frozen 
  287. once it is full as for LZW - the program continually monitors compression 
  288. performance, and once this starts decreasing the entire dictionary is 
  289. discarded and rebuilt from scratch.  More recent schemes use some sort of 
  290. least-recently-used algorithm to discard little-used phrases once the 
  291. dictionary becomes full rather than throwing away the entire dictionary.  
  292.  
  293. Finally, not all schemes build up the dictionary by adding a single new 
  294. character to the end of the current phrase. An alternative technique is to 
  295. concatenate the previous two phrases (LZMW), which results in a faster 
  296. buildup of longer phrases than the character-by-character buildup of the 
  297. other methods.  The disadvantage of this method is that a more sophisticated 
  298. data structure is needed to handle the dictionary.
  299.  
  300. [A good introduction to LZW, MW, AP and Y coding is given in the yabba
  301. package. For ftp information, see question 2 in part one, file type .Y]
  302.  
  303.  
  304. <The LZ77 family of compressors>
  305.  
  306.   LZ77-based schemes keep track of the last n bytes of data seen, and when a 
  307. phrase is encountered that has already been seen, they output a pair of 
  308. values corresponding to the position of the phrase in the previously-seen 
  309. buffer of data, and the length of the phrase.  In effect the compressor moves 
  310. a fixed-size *window* over the data (generally referred to as a *sliding 
  311. window*), with the position part of the (position, length) pair referring to 
  312. the position of the phrase within the window.  The most commonly used 
  313. algorithms are derived from the LZSS scheme described by James Storer and 
  314. Thomas Szymanski in 1982.  In this the compressor maintains a window of size 
  315. N bytes and a *lookahead buffer* the contents of which it tries to find a 
  316. match for in the window:
  317.  
  318.   while( lookAheadBuffer not empty )
  319.       {
  320.       get a pointer ( position, match ) to the longest match in the window
  321.           for the lookahead buffer;
  322.  
  323.       if( length > MINIMUM_MATCH_LENGTH )
  324.           {
  325.           output a ( position, length ) pair;
  326.           shift the window length characters along;
  327.           }
  328.       else
  329.           {
  330.           output the first character in the lookahead buffer;
  331.           shift the window 1 character along;
  332.           }
  333.       }
  334.         
  335.   Decompression is simple and fast:  Whenever a ( position, length ) pair is 
  336. encountered, go to that ( position ) in the window and copy ( length ) bytes 
  337. to the output.
  338.  
  339.   Sliding-window-based schemes can be simplified by numbering the input text
  340. characters mod N, in effect creating a circular buffer.  The sliding window
  341. approach automatically creates the LRU effect which must be done explicitly in
  342. LZ78 schemes.  Variants of this method apply additional compression to the
  343. output of the LZSS compressor, which include a simple variable-length code
  344. (LZB), dynamic Huffman coding (LZH), and Shannon-Fano coding (ZIP 1.x)), all
  345. of which result in a certain degree of improvement over the basic scheme,
  346. especially when the data are rather random and the LZSS compressor has little
  347. effect.
  348.   Recently an algorithm was developed which combines the ideas behind LZ77 and
  349. LZ78 to produce a hybrid called LZFG.  LZFG uses the standard sliding window,
  350. but stores the data in a modified trie data structure and produces as output
  351. the position of the text in the trie.  Since LZFG only inserts complete
  352. *phrases* into the dictionary, it should run faster than other LZ77-based
  353. compressors.
  354.  
  355. All popular archivers (arj, lha, zip, zoo) are variations on the LZ77 theme.
  356.  
  357. ------------------------------------------------------------------------------
  358.  
  359. Subject: [71] Introduction to MPEG (long)
  360.  
  361.  
  362. For MPEG players, see item 15 in part 1 of the FAQ.  Frank Gadegast
  363. <phade@cs.tu-berlin.de> also posts a FAQ specialized in MPEG, available in
  364. ftp.cs.tu-berlin.de:/pub/msdos/windows3/graphics/mpegfa*.zip.
  365. Chad Fogg <cfogg@ole.cdac.com> also has another FAQ in preparation.
  366. The site ftp.crs4.it dedicated to the MPEG compression standard,
  367. see the directory mpeg and subdirectories.
  368.  
  369.  
  370. Introduction to MPEG originally written by Mark Adler 
  371. <madler@cco.caltech.edu> around January 1992; modified and updated by 
  372. Harald Popp <layer3@iis.fhg.de> in March 94:
  373.  
  374. Q: What is MPEG, exactly?
  375.  
  376. A: MPEG is the "Moving Picture Experts Group", working under the 
  377.    joint direction of the International Standards Organization (ISO) 
  378.    and the International Electro-Technical Commission (IEC). This 
  379.    group works on standards for the coding of moving pictures and 
  380.    associated audio.
  381.  
  382. Q: What is the status of MPEG's work, then? What's about MPEG-1, -2, 
  383.    and so on?
  384.  
  385. A: MPEG approaches the growing need for multimedia standards step-by-
  386.    step. Today, three "phases" are defined:
  387.    
  388.    MPEG-1: "Coding of Moving Pictures and Associated Audio for 
  389.            Digital Storage Media at up to about 1.5 MBit/s"  
  390.  
  391.    Status: International Standard IS-11172, completed in 10.92
  392.    
  393.    MPEG-2: "Generic Coding of Moving Pictures and Associated Audio"
  394.    
  395.    Status: Comittee Draft CD 13818 as found in documents MPEG93 / 
  396.            N601, N602, N603 (11.93)   
  397.  
  398.    MPEG-3: does not longer exist (has been merged into MPEG-2)
  399.    
  400.    MPEG-4: "Very Low Bitrate Audio-Visual Coding"
  401.    
  402.    Status: Call for Proposals 11.94, Working Draft in 11.96 
  403.  
  404. Q: MPEG-1 is ready-for-use. How does the standard look like?
  405.  
  406. A: MPEG-1 consists of 4 parts:
  407.  
  408.    IS 11172-1: System
  409.    describes synchronization and multiplexing of video and audio
  410.  
  411.    IS 11172-2: Video
  412.    describes compression of non-interlaced video signals
  413.    
  414.    IS 11172-3: Audio
  415.    describes compression of audio signals 
  416.    
  417.    CD 11172-4: Compliance Testing
  418.    describes procedures for determining the characteristics of coded 
  419.    bitstreams and the decoding porcess and for testing compliance 
  420.    with the requirements stated in the other parts
  421.  
  422. Q. Does MPEG have anything to do with JPEG? 
  423.  
  424. A. Well, it sounds the same, and they are part of the same 
  425.    subcommittee of ISO along with JBIG and MHEG, and they usually meet 
  426.    at the same place at the same time.  However, they are different 
  427.    sets of people with few or no common individual members, and they 
  428.    have different charters and requirements.  JPEG is for still image 
  429.    compression.
  430.  
  431. Q. Then what's JBIG and MHEG?
  432.  
  433. A. Sorry I mentioned them. Ok, I'll simply say that JBIG is for binary
  434.    image compression (like faxes), and MHEG is for multi-media data
  435.    standards (like integrating stills, video, audio, text, etc.).
  436.    For an introduction to JBIG, see question 74 below.
  437.  
  438. Q. So how does MPEG-1 work? Tell me about video coding!
  439.  
  440. A. First off, it starts with a relatively low resolution video
  441.    sequence (possibly decimated from the original) of about 352 by
  442.    240 frames by 30 frames/s (US--different numbers for Europe),
  443.    but original high (CD) quality audio.  The images are in color,
  444.    but converted to YUV space, and the two chrominance channels
  445.    (U and V) are decimated further to 176 by 120 pixels.  It turns
  446.    out that you can get away with a lot less resolution in those
  447.    channels and not notice it, at least in "natural" (not computer
  448.    generated) images.
  449.  
  450.    The basic scheme is to predict motion from frame to frame in the
  451.    temporal direction, and then to use DCT's (discrete cosine
  452.    transforms) to organize the redundancy in the spatial directions.
  453.    The DCT's are done on 8x8 blocks, and the motion prediction is
  454.    done in the luminance (Y) channel on 16x16 blocks.  In other words,
  455.    given the 16x16 block in the current frame that you are trying to
  456.    code, you look for a close match to that block in a previous or
  457.    future frame (there are backward prediction modes where later
  458.    frames are sent first to allow interpolating between frames).
  459.    The DCT coefficients (of either the actual data, or the difference
  460.    between this block and the close match) are "quantized", which
  461.    means that you divide them by some value to drop bits off the
  462.    bottom end.  Hopefully, many of the coefficients will then end up
  463.    being zero.  The quantization can change for every "macroblock"
  464.    (a macroblock is 16x16 of Y and the corresponding 8x8's in both
  465.    U and V).  The results of all of this, which include the DCT
  466.    coefficients, the motion vectors, and the quantization parameters
  467.    (and other stuff) is Huffman coded using fixed tables.  The DCT
  468.    coefficients have a special Huffman table that is "two-dimensional"
  469.    in that one code specifies a run-length of zeros and the non-zero
  470.    value that ended the run.  Also, the motion vectors and the DC
  471.    DCT components are DPCM (subtracted from the last one) coded.
  472.  
  473. Q. So is each frame predicted from the last frame?
  474.  
  475. A. No.  The scheme is a little more complicated than that.  There are
  476.    three types of coded frames.  There are "I" or intra frames.  They
  477.    are simply a frame coded as a still image, not using any past
  478.    history.  You have to start somewhere.  Then there are "P" or
  479.    predicted frames.  They are predicted from the most recently
  480.    reconstructed I or P frame.  (I'm describing this from the point
  481.    of view of the decompressor.)  Each macroblock in a P frame can
  482.    either come with a vector and difference DCT coefficients for a
  483.    close match in the last I or P, or it can just be "intra" coded
  484.    (like in the I frames) if there was no good match.
  485.  
  486.    Lastly, there are "B" or bidirectional frames.  They are predicted
  487.    from the closest two I or P frames, one in the past and one in the
  488.    future.  You search for matching blocks in those frames, and try
  489.    three different things to see which works best.  (Now I have the
  490.    point of view of the compressor, just to confuse you.)  You try 
  491.    using the forward vector, the backward vector, and you try 
  492.    averaging the two blocks from the future and past frames, and 
  493.    subtracting that from the block being coded.  If none of those work 
  494.    well, you can intracode the block.
  495.  
  496.    The sequence of decoded frames usually goes like:
  497.  
  498.    IBBPBBPBBPBBIBBPBBPB...
  499.  
  500.    Where there are 12 frames from I to I (for US and Japan anyway.)
  501.    This is based on a random access requirement that you need a
  502.    starting point at least once every 0.4 seconds or so.  The ratio
  503.    of P's to B's is based on experience.
  504.  
  505.    Of course, for the decoder to work, you have to send that first
  506.    P *before* the first two B's, so the compressed data stream ends
  507.    up looking like:
  508.  
  509.    0xx312645...
  510.  
  511.    where those are frame numbers.  xx might be nothing (if this is
  512.    the true starting point), or it might be the B's of frames -2 and
  513.    -1 if we're in the middle of the stream somewhere.
  514.  
  515.    You have to decode the I, then decode the P, keep both of those
  516.    in memory, and then decode the two B's.  You probably display the
  517.    I while you're decoding the P, and display the B's as you're
  518.    decoding them, and then display the P as you're decoding the next
  519.    P, and so on.
  520.  
  521. Q. You've got to be kidding.
  522.  
  523. A. No, really!
  524.  
  525. Q. Hmm.  Where did they get 352x240?
  526.  
  527. A. That derives from the CCIR-601 digital television standard which
  528.    is used by professional digital video equipment.  It is (in the US)
  529.    720 by 243 by 60 fields (not frames) per second, where the fields
  530.    are interlaced when displayed.  (It is important to note though
  531.    that fields are actually acquired and displayed a 60th of a second
  532.    apart.)  The chrominance channels are 360 by 243 by 60 fields a
  533.    second, again interlaced.  This degree of chrominance decimation
  534.    (2:1 in the horizontal direction) is called 4:2:2.  The source
  535.    input format for MPEG I, called SIF, is CCIR-601 decimated by 2:1
  536.    in the horizontal direction, 2:1 in the time direction, and an
  537.    additional 2:1 in the chrominance vertical direction.  And some
  538.    lines are cut off to make sure things divide by 8 or 16 where
  539.    needed.
  540.  
  541. Q. What if I'm in Europe?
  542.  
  543. A. For 50 Hz display standards (PAL, SECAM) change the number of lines
  544.    in a field from 243 or 240 to 288, and change the display rate to
  545.    50 fields/s or 25 frames/s.  Similarly, change the 120 lines in
  546.    the decimated chrominance channels to 144 lines.  Since 288*50 is
  547.    exactly equal to 240*60, the two formats have the same source data
  548.    rate.
  549.  
  550. Q. What will MPEG-2 do for video coding?
  551.  
  552. A. As I said, there is a considerable loss of quality in going from
  553.    CCIR-601 to SIF resolution.  For entertainment video, it's simply
  554.    not acceptable.  You want to use more bits and code all or almost
  555.    all the CCIR-601 data.  From subjective testing at the Japan
  556.    meeting in November 1991, it seems that 4 MBits/s can give very
  557.    good quality compared to the original CCIR-601 material.  The
  558.    objective of MPEG-2 is to define a bit stream optimized for 
  559.    these resolutions and bit rates.
  560.  
  561. Q. Why not just scale up what you're doing with MPEG-1?
  562.  
  563. A. The main difficulty is the interlacing.  The simplest way to extend
  564.    MPEG-1 to interlaced material is to put the fields together into
  565.    frames (720x486x30/s).  This results in bad motion artifacts that
  566.    stem from the fact that moving objects are in different places
  567.    in the two fields, and so don't line up in the frames.  Compressing
  568.    and decompressing without taking that into account somehow tends to
  569.    muddle the objects in the two different fields.
  570.  
  571.    The other thing you might try is to code the even and odd field
  572.    streams separately.  This avoids the motion artifacts, but as you
  573.    might imagine, doesn't get very good compression since you are not
  574.    using the redundancy between the even and odd fields where there
  575.    is not much motion (which is typically most of image).
  576.  
  577.    Or you can code it as a single stream of fields.  Or you can
  578.    interpolate lines.  Or, etc. etc.  There are many things you can
  579.    try, and the point of MPEG-2 is to figure out what works well.
  580.    MPEG-2 is not limited to consider only derivations of MPEG-1.
  581.    There were several non-MPEG-1-like schemes in the competition in
  582.    November, and some aspects of those algorithms may or may not
  583.    make it into the final standard for entertainment video 
  584.    compression.
  585.  
  586. Q. So what works?
  587.  
  588. A. Basically, derivations of MPEG-1 worked quite well, with one that
  589.    used wavelet subband coding instead of DCT's that also worked very
  590.    well.  Also among the worked-very-well's was a scheme that did not
  591.    use B frames at all, just I and P's.  All of them, except maybe 
  592.    one, did some sort of adaptive frame/field coding, where a decision 
  593.    is made on a macroblock basis as to whether to code that one as 
  594.    one frame macroblock or as two field macroblocks.  Some other 
  595.    aspects are how to code I-frames--some suggest predicting the even 
  596.    field from the odd field.  Or you can predict evens from evens and 
  597.    odds or odds from evens and odds or any field from any other field, 
  598.    etc.
  599.  
  600. Q. So what works?
  601.  
  602. A. Ok, we're not really sure what works best yet.  The next step is
  603.    to define a "test model" to start from, that incorporates most of
  604.    the salient features of the worked-very-well proposals in a
  605.    simple way.  Then experiments will be done on that test model,
  606.    making a mod at a time, and seeing what makes it better and what
  607.    makes it worse.  Example experiments are, B's or no B's, DCT vs.
  608.    wavelets, various field prediction modes, etc.  The requirements,
  609.    such as implementation cost, quality, random access, etc. will all
  610.    feed into this process as well.
  611.  
  612. Q. When will all this be finished?
  613.  
  614. A. I don't know.  I'd have to hope in about a year or less.
  615.  
  616. Q: Talking about MPEG audio coding, I heard a lot about "Layer 1, 2 
  617.    and 3". What does it mean, exactly?   
  618.  
  619. A: MPEG-1, IS 11172-3, describes the compression of audio signals 
  620.    using high performance perceptual coding schemes. It specifies a 
  621.    family of three audio coding schemes, simply called Layer-1,-2,-3, 
  622.    with increasing encoder complexity and performance (sound quality 
  623.    per bitrate). The three codecs are compatible in a hierarchical 
  624.    way, i.e. a Layer-N decoder is able to decode bitstream data 
  625.    encoded in Layer-N and all Layers below N (e.g., a Layer-3 
  626.    decoder may accept Layer-1,-2 and -3, whereas a Layer-2 decoder 
  627.    may accept only Layer-1 and -2.)
  628.  
  629. Q: So we have a family of three audio coding schemes. What does the 
  630.    MPEG standard define, exactly?
  631.    
  632. A: For each Layer, the standard specifies the bitstream format and 
  633.    the decoder. To allow for future improvements, it does *not* 
  634.    specify the encoder , but an informative chapter gives an example 
  635.    for an encoder for each Layer.    
  636.  
  637. Q: What have the three audio Layers in common?
  638.  
  639. A: All Layers use the same basic structure. The coding scheme can be  
  640.    described as "perceptual noise shaping" or "perceptual subband / 
  641.    transform coding". 
  642.  
  643.    The encoder analyzes the spectral components of the audio signal 
  644.    by calculating a filterbank or transform and applies a 
  645.    psychoacoustic model to estimate the just noticeable noise-
  646.    level. In its quantization and coding stage, the encoder tries 
  647.    to allocate the available number of data bits in a way to meet 
  648.    both the bitrate and masking requirements.
  649.  
  650.    The decoder is much less complex. Its only task is to synthesize 
  651.    an audio signal out of the coded spectral components.
  652.    
  653.    All Layers use the same analysis filterbank (polyphase with 32 
  654.    subbands). Layer-3 adds a MDCT transform to increase the frequency 
  655.    resolution.
  656.    
  657.    All Layers use the same "header information" in their bitstream, 
  658.    to support the hierarchical structure of the standard.
  659.    
  660.    All Layers use a bitstream structure that contains parts that are 
  661.    more sensitive to biterrors ("header", "bit allocation", 
  662.    "scalefactors", "side information") and parts that are less 
  663.    sensitive ("data of spectral components").  
  664.  
  665.    All Layers may use 32, 44.1 or 48 kHz sampling frequency.
  666.    
  667.    All Layers are allowed to work with similar bitrates:
  668.    Layer-1: from 32 kbps to 448 kbps
  669.    Layer-2: from 32 kbps to 384 kbps
  670.    Layer-3: from 32 kbps to 320 kbps
  671.  
  672. Q: What are the main differences between the three Layers, from a 
  673.    global view?
  674.  
  675. A: From Layer-1 to Layer-3,
  676.    complexity increases (mainly true for the encoder),
  677.    overall codec delay increases, and
  678.    performance increases (sound quality per bitrate).
  679.  
  680. Q: Which Layer should I use for my application?
  681.  
  682. A: Good Question. Of course, it depends on all your requirements. But 
  683.    as a first approach, you should consider the available bitrate of 
  684.    your application as the Layers have been designed to support 
  685.    certain areas of bitrates most efficiently, i.e. with a minimum 
  686.    drop of sound quality.
  687.  
  688.    Let us look a little closer at the strong domains of each Layer.
  689.     
  690.    Layer-1: Its ISO target bitrate is 192 kbps per audio channel.
  691.  
  692.    Layer-1 is a simplified version of Layer-2. It is most useful for 
  693.    bitrates around the "high" bitrates around or above 192 kbps. A 
  694.    version of Layer-1 is used as "PASC" with the DCC recorder.
  695.  
  696.    Layer-2: Its ISO target bitrate is 128 kbps per audio channel.
  697.    
  698.    Layer-2 is identical with MUSICAM. It has been designed as trade-
  699.    off between sound quality per bitrate and encoder complexity. It 
  700.    is most useful for bitrates around the "medium" bitrates of 128 or 
  701.    even 96 kbps per audio channel. The DAB (EU 147) proponents have 
  702.    decided to use Layer-2 in the future Digital Audio Broadcasting 
  703.    network.      
  704.  
  705.    Layer-3: Its ISO target bitrate is 64 kbps per audio channel.
  706.    
  707.    Layer-3 merges the best ideas of MUSICAM and ASPEC. It has been 
  708.    designed for best performance at "low" bitrates around 64 kbps or 
  709.    even below. The Layer-3 format specifies a set of advanced 
  710.    features that all address one goal: to preserve as much sound 
  711.    quality as possible even at rather low bitrates. Today, Layer-3 is 
  712.    already in use in various telecommunication networks (ISDN, 
  713.    satellite links, and so on) and speech announcement systems. 
  714.  
  715. Q: Tell me more about sound quality. How do you assess that?
  716.  
  717. A: Today, there is no alternative to expensive listening tests. 
  718.    During the ISO-MPEG-1 process, 3 international listening tests 
  719.    have been performed, with a lot of trained listeners, supervised 
  720.    by Swedish Radio. They took place in 7.90, 3.91 and 11.91. Another 
  721.    international listening test was performed by CCIR, now ITU-R, in 
  722.    92.      
  723.    
  724.    All these tests used the "triple stimulus, hidden reference" 
  725.    method and the CCIR impairment scale to assess the audio quality.
  726.    The listening sequence is "ABC", with A = original, BC = pair of 
  727.    original / coded signal with random sequence, and the listener has 
  728.    to evaluate both B and C with a number between 1.0 and 5.0. The 
  729.    meaning of these values is:
  730.    
  731.    5.0 = transparent (this should be the original signal)
  732.    4.0 = perceptible, but not annoying (first differences noticable)  
  733.    3.0 = slightly annoying   
  734.    2.0 = annoying
  735.    1.0 = very annoying
  736.  
  737.    With perceptual codecs (like MPEG audio), all traditional 
  738.    parameters (like SNR, THD+N, bandwidth) are especially useless. 
  739.    Fraunhofer-IIS works on objective quality assessment tools, like 
  740.    the NMR meter (Noise-to-Mask-Ratio), too. BTW: If you need more 
  741.    informations about NMR, please contact nmr@iis.fhg.de.
  742.  
  743. Q: Now that I know how to assess quality, come on, tell me the 
  744.    results of these tests.
  745.    
  746. A: Well, for low bitrates, the main result is that at 60 or 64 kbps 
  747.    per channel), Layer-2 scored always between 2.1 and 2.6, whereas 
  748.    Layer-3 scored between 3.6 and 3.8. This is a significant increase 
  749.    in sound quality, indeed! Furthermore, the selection process for 
  750.    critical sound material showed that it was rather difficult to 
  751.    find worst-case material for Layer-3 whereas it was not so hard to 
  752.    find such items for Layer-2.
  753.   
  754. Q: OK, a Layer-2 codec at low bitrates may sound poor today, but 
  755.    couldn't that be improved in the future? I guess you just told me 
  756.    before that the encoder is not fixed in the standard.
  757.    
  758. A: Good thinking! As the sound quality mainly depends on the encoder 
  759.    implementation, it is true that there is no such thing as a "Layer-
  760.    N"- quality. So we definitely only know the performance of the 
  761.    reference codecs during the international tests. Who knows what 
  762.    will happen in the future? What we do know now, is:
  763.    
  764.    Today, Layer-3 already provides a sound quality that comes very 
  765.    near to CD quality at 64 kbps per channel. Layer-2 is far away 
  766.    from that.
  767.    
  768.    Tomorrow, both Layers may improve. Layer-2 has been designed as a 
  769.    trade-off between quality and complexity, so the bitstream format 
  770.    allows only limited innovations. In contrast, even the current
  771.    reference Layer-3-codec exploits only a small part of the powerful 
  772.    mechanisms inside the Layer-3 bitstream format.  
  773.  
  774. Q: All in all, you sound as if anybody should use Layer-3 for low 
  775.    bitrates. Why on earth do some vendors still offer only Layer-2 
  776.    equipment for these applications?
  777.    
  778. A: Well, maybe because they started to design and develop their 
  779.    system rather early, e.g. in 1990. As Layer-2 is identical with 
  780.    MUSICAM, it has been available since summer of 90, at latest. In 
  781.    that year, Layer-3 development started and could be successfully 
  782.    finished in spring 92. So, for a certain time, vendors could only 
  783.    exploit the existing part of the new MPEG standard.   
  784.    
  785.    Now the situation has changed. All Layers are available, the 
  786.    standard is completed, and new systems need not limit themselves, 
  787.    but may capitalize on the full features of MPEG audio.
  788.  
  789. Q: How do I get the MPEG documents?
  790.  
  791. A: You may order it from your national standards body.
  792.  
  793.    E.g., in Germany, please contact:
  794.    DIN-Beuth Verlag, Auslandsnormen
  795.    Mrs. Niehoff, Burggrafenstr. 6, D-10772 Berlin, Germany
  796.    Phone: 030-2601-2757, Fax: 030-2601-1231
  797.  
  798.    E.g., in USA, you may order it from ANSI or 
  799.    buy it from companies like OMNICOM phone +44 438 742424
  800.                                       FAX   +44 438 740154
  801.  
  802. Q. How do I join MPEG?
  803.  
  804. A. You don't join MPEG.  You have to participate in ISO as part of a
  805.    national delegation.  How you get to be part of the national
  806.    delegation is up to each nation.  I only know the U.S., where you
  807.    have to attend the corresponding ANSI meetings to be able to
  808.    attend the ISO meetings.  Your company or institution has to be
  809.    willing to sink some bucks into travel since, naturally, these
  810.    meetings are held all over the world.  (For example, Paris,
  811.    Santa Clara, Kurihama Japan, Singapore, Haifa Israel, Rio de
  812.    Janeiro, London, etc.)
  813.  
  814. ------------------------------------------------------------------------------
  815.  
  816. Subject: [72] What is wavelet theory?
  817.  
  818.  
  819. Preprints and software are available by anonymous ftp from the
  820. Yale Mathematics Department computer ceres.math.yale.edu[130.132.23.22],
  821. in pub/wavelets and pub/software.
  822.  
  823. epic and hcompress are wavelet coders. (For source code, see item 15
  824. in part one).
  825.  
  826. Bill Press of Harvard/CfA has made some things available for anonymous
  827. ftp on cfata4.harvard.edu [128.103.40.79] in directory /pub. There is
  828. a short TeX article on wavelet theory (wavelet.tex, to be included in
  829. a future edition of Numerical Recipes), some sample wavelet code
  830. (wavelet.f, in FORTRAN - sigh), and a beta version of an astronomical
  831. image compression program which he is currently developing (FITS
  832. format data files only, in fitspress08.tar.Z).
  833.  
  834. The Rice Wavelet Toolbox Release 2.0 is available on cml.rice.edu in
  835. directories /pub/dsp/software and /pub/dsp/papers.  This is a
  836. collection of MATLAB of "mfiles" and "mex" files for twoband and
  837. M-band filter bank/wavelet analysis from the DSP group and
  838. Computational Mathematics Laboratory (CML) at Rice University,
  839. Houston, TX.  This release includes application code for Synthetic
  840. Aperture Radar despeckling and for deblocking of JPEG decompressed
  841. Images.  Contact: Ramesh Gopinath <ramesh@rice.edu>.
  842.  
  843.  
  844. A mailing list dedicated to research on wavelets has been set up at the
  845. University of South Carolina. To subscribe to this mailing list, send a
  846. message with "subscribe" as the subject to wavelet@math.scarolina.edu.
  847.  
  848.  
  849. A 5 minute course in wavelet transforms, by Richard Kirk <rak@crosfield.co.uk>:
  850.  
  851. Do you know what a Haar transform is? Its a transform to another orthonormal
  852. space (like the DFT), but the basis functions are a set of square wave bursts
  853. like this...
  854.  
  855.    +--+                         +------+
  856.    +  |  +------------------    +      |      +--------------
  857.       +--+                             +------+
  858.  
  859.          +--+                                 +------+
  860.    ------+  |  +------------    --------------+      |      +
  861.             +--+                                     +------+
  862.  
  863.                +--+             +-------------+
  864.    ------------+  |  +------    +             |             +
  865.                   +--+                        +-------------+
  866.  
  867.                      +--+       +---------------------------+
  868.    ------------------+  |  +    +                           +
  869.                         +--+
  870.  
  871. This is the set of functions for an 8-element 1-D Haar transform. You
  872. can probably see how to extend this to higher orders and higher dimensions
  873. yourself. This is dead easy to calculate, but it is not what is usually
  874. understood by a wavelet transform.
  875.  
  876. If you look at the eight Haar functions you see we have four functions
  877. that code the highest resolution detail, two functions that code the
  878. coarser detail, one function that codes the coarser detail still, and the 
  879. top function that codes the average value for the whole `image'.
  880.  
  881. Haar function can be used to code images instead of the DFT. With bilevel
  882. images (such as text) the result can look better, and it is quicker to code.
  883. Flattish regions, textures, and soft edges in scanned images get a nasty
  884. `blocking' feel to them. This is obvious on hardcopy, but can be disguised on
  885. color CRTs by the effects of the shadow mask. The DCT gives more consistent
  886. results.
  887.  
  888. This connects up with another bit of maths sometimes called Multispectral
  889. Image Analysis, sometimes called Image Pyramids.
  890.  
  891. Suppose you want to produce a discretely sampled image from a continuous 
  892. function. You would do this by effectively `scanning' the function using a
  893. sinc function [ sin(x)/x ] `aperture'. This was proved by Shannon in the 
  894. `forties. You can do the same thing starting with a high resolution
  895. discretely sampled image. You can then get a whole set of images showing 
  896. the edges at different resolutions by differencing the image at one
  897. resolution with another version at another resolution. If you have made this
  898. set of images properly they ought to all add together to give the original 
  899. image.
  900.  
  901. This is an expansion of data. Suppose you started off with a 1K*1K image.
  902. You now may have a 64*64 low resolution image plus difference images at 128*128
  903. 256*256, 512*512 and 1K*1K. 
  904.  
  905. Where has this extra data come from? If you look at the difference images you 
  906. will see there is obviously some redundancy as most of the values are near 
  907. zero. From the way we constructed the levels we know that locally the average
  908. must approach zero in all levels but the top. We could then construct a set of
  909. functions out of the sync functions at any level so that their total value 
  910. at all higher levels is zero. This gives us an orthonormal set of basis 
  911. functions for a transform. The transform resembles the Haar transform a bit,
  912. but has symmetric wave pulses that decay away continuously in either direction
  913. rather than square waves that cut off sharply. This transform is the
  914. wavelet transform ( got to the point at last!! ).
  915.  
  916. These wavelet functions have been likened to the edge detecting functions
  917. believed to be present in the human retina.
  918.  
  919.  
  920. Loren I. Petrich <lip@s1.gov> adds that order 2 or 3 Daubechies
  921. discrete wavelet transforms have a speed comparable to DCT's, and
  922. usually achieve compression a factor of 2 better for the same image
  923. quality than the JPEG 8*8 DCT. (See item 25 in part 1 of this FAQ for
  924. references on fast DCT algorithms.)
  925.  
  926. ------------------------------------------------------------------------------
  927.  
  928. Subject: [73] What is the theoretical compression limit?
  929.  
  930.  
  931. There is no compressor that is guaranteed to compress all possible input
  932. files. If it compresses some files, then it must enlarge some others.
  933. This can be proven by a simple counting argument (see question 9).
  934.  
  935. As an extreme example, the following algorithm achieves optimal
  936. compression for one special input file and enlarges all other files by
  937. only one bit:
  938.  
  939. - if the input data is <insert your favorite one here>, output a single 0 bit
  940. - otherwise output the bit 1 followed by the input data.
  941.  
  942. (You can even output an empty file in the first case if the decompressor
  943. can detect by other means that the input is empty.)
  944.  
  945. The concept of theoretical compression limit is meaningful only
  946. if you have a model for your input data. See question 70 above
  947. for some examples of data models.
  948.  
  949. ------------------------------------------------------------------------------
  950.  
  951. Subject: [74] Introduction to JBIG
  952.  
  953.  
  954. JBIG software and the JBIG specification are available on nic.funet.fi
  955. in /pub/graphics/misc/test-images/jbig.tar.gz.
  956.  
  957.  
  958. A short introduction to JBIG, written by Mark Adler <madler@cco.caltech.edu>:
  959.  
  960.   JBIG losslessly compresses binary (one-bit/pixel) images.  (The B stands
  961.   for bi-level.)  Basically it models the redundancy in the image as the
  962.   correlations of the pixel currently being coded with a set of nearby
  963.   pixels called the template.  An example template might be the two
  964.   pixels preceding this one on the same line, and the five pixels centered
  965.   above this pixel on the previous line.  Note that this choice only
  966.   involves pixels that have already been seen from a scanner.
  967.  
  968.   The current pixel is then arithmetically coded based on the eight-bit
  969.   (including the pixel being coded) state so formed.  So there are (in this
  970.   case) 256 contexts to be coded.  The arithmetic coder and probability
  971.   estimator for the contexts are actually IBM's (patented) Q-coder.  The
  972.   Q-coder uses low precision, rapidly adaptable (those two are related)
  973.   probability estimation combined with a multiply-less arithmetic coder.
  974.   The probability estimation is intimately tied to the interval calculations
  975.   necessary for the arithmetic coding.
  976.  
  977.   JBIG actually goes beyond this and has adaptive templates, and probably
  978.   some other bells and whistles I don't know about.  You can find a
  979.   description of the Q-coder as well as the ancestor of JBIG in the Nov 88
  980.   issue of the IBM Journal of Research and Development.  This is a very
  981.   complete and well written set of five articles that describe the Q-coder
  982.   and a bi-level image coder that uses the Q-coder.
  983.  
  984.   You can use JBIG on grey-scale or even color images by simply applying
  985.   the algorithm one bit-plane at a time.  You would want to recode the
  986.   grey or color levels first though, so that adjacent levels differ in
  987.   only one bit (called Gray-coding).  I hear that this works well up to
  988.   about six bits per pixel, beyond which JPEG's lossless mode works better.
  989.   You need to use the Q-coder with JPEG also to get this performance.
  990.  
  991.   Actually no lossless mode works well beyond six bits per pixel, since
  992.   those low bits tend to be noise, which doesn't compress at all.
  993.  
  994.   Anyway, the intent of JBIG is to replace the current, less effective
  995.   group 3 and 4 fax algorithms.
  996.  
  997.  
  998. Another introduction to JBIG, written by Hank van Bekkem <jbek@oce.nl>:
  999.  
  1000.   The following description of the JBIG algorithm is derived from
  1001.   experiences with a software implementation I wrote following the
  1002.   specifications in the revision 4.1 draft of September 16, 1991. The
  1003.   source will not be made available in the public domain, as parts of
  1004.   JBIG are patented.
  1005.  
  1006.   JBIG (Joint Bi-level Image Experts Group) is an experts group of ISO,
  1007.   IEC and CCITT (JTC1/SC2/WG9 and SGVIII). Its job is to define a
  1008.   compression standard for lossless image coding ([1]). The main
  1009.   characteristics of the proposed algorithm are:
  1010.   - Compatible progressive/sequential coding. This means that a
  1011.     progressively coded image can be decoded sequentially, and the
  1012.     other way around.
  1013.   - JBIG will be a lossless image compression standard: all bits in
  1014.     your images before and after compression and decompression will be
  1015.     exactly the same.
  1016.  
  1017.   In the rest of this text I will first describe the JBIG algorithm in
  1018.   a short abstract of the draft. I will conclude by saying something
  1019.   about the value of JBIG.
  1020.  
  1021.  
  1022.   JBIG algorithm.
  1023.   --------------
  1024.  
  1025.   JBIG parameter P specifies the number of bits per pixel in the image.
  1026.   Its allowable range is 1 through 255, but starting at P=8 or so,
  1027.   compression will be more efficient using other algorithms. On the
  1028.   other hand, medical images such as chest X-rays are often stored with
  1029.   12 bits per pixel, while no distorsion is allowed, so JBIG can
  1030.   certainly be of use in this area. To limit the number of bit changes
  1031.   between adjacent decimal values (e.g. 127 and 128), it is wise to use
  1032.   Gray coding before compressing multi-level images with JBIG. JBIG
  1033.   then compresses the image on a bitplane basis, so the rest of this
  1034.   text assumes bi-level pixels.
  1035.  
  1036.   Progressive coding is a way to send an image gradually to a receiver
  1037.   instead of all at once. During sending, more detail is sent, and the
  1038.   receiver can build the image from low to high detail. JBIG uses
  1039.   discrete steps of detail by successively doubling the resolution. The
  1040.   sender computes a number of resolution layers D, and transmits these
  1041.   starting at the lowest resolution Dl. Resolution reduction uses
  1042.   pixels in the high resolution layer and some already computed low
  1043.   resolution pixels as an index into a lookup table. The contents of
  1044.   this table can be specified by the user.
  1045.  
  1046.   Compatibility between progressive and sequential coding is achieved
  1047.   by dividing an image into stripes. Each stripe is a horizontal bar
  1048.   with a user definable height. Each stripe is separately coded and
  1049.   transmitted, and the user can define in which order stripes,
  1050.   resolutions and bitplanes (if P>1) are intermixed in the coded data.
  1051.   A progressive coded image can be decoded sequentially by decoding
  1052.   each stripe, beginning by the one at the top of the image, to its
  1053.   full resolution, and then proceeding to the next stripe. Progressive
  1054.   decoding can be done by decoding only a specific resolution layer
  1055.   from all stripes.
  1056.  
  1057.   After dividing an image into bitplanes, resolution layers and
  1058.   stripes, eventually a number of small bi-level bitmaps are left to
  1059.   compress. Compression is done using a Q-coder. Reference [2]
  1060.   contains a full description, I will only outline the basic principles
  1061.   here.
  1062.  
  1063.   The Q-coder codes bi-level pixels as symbols using the probability of
  1064.   occurrence of these symbols in a certain context. JBIG defines two
  1065.   kinds of context, one for the lowest resolution layer (the base
  1066.   layer), and one for all other layers (differential layers).
  1067.   Differential layer contexts contain pixels in the layer to be coded,
  1068.   and in the corresponding lower resolution layer.
  1069.  
  1070.   For each combination of pixel values in a context, the probability
  1071.   distribution of black and white pixels can be different. In an all
  1072.   white context, the probability of coding a white pixel will be much
  1073.   greater than that of coding a black pixel. The Q-coder assigns, just
  1074.   like a Huffman coder, more bits to less probable symbols, and so
  1075.   achieves compression. The Q-coder can, unlike a Huffmann coder,
  1076.   assign one output codebit to more than one input symbol, and thus is
  1077.   able to compress bi-level pixels without explicit clustering, as
  1078.   would be necessary using a Huffman coder.
  1079.  
  1080.   Maximum compression will be achieved when all probabilities (one set
  1081.   for each combination of pixel values in the context) follow the
  1082.   probabilities of the pixels. The Q-coder therefore continuously
  1083.   adapts these probabilities to the symbols it sees.
  1084.  
  1085.  
  1086.   JBIG value.
  1087.   ----------
  1088.  
  1089.   In my opinion, JBIG can be regarded as two combined devices:
  1090.   - Providing the user the service of sending or storing multiple
  1091.     representations of images at different resolutions without any
  1092.     extra cost in storage. Differential layer contexts contain pixels
  1093.     in two resolution layers, and so enable the Q-coder to effectively
  1094.     code the difference in information between the two layers, instead
  1095.     of the information contained in every layer. This means that,
  1096.     within a margin of approximately 5%, the number of resolution
  1097.     layers doesn't effect the compression ratio.
  1098.   - Providing the user a very efficient compression algorithm, mainly
  1099.     for use with bi-level images. Compared to CCITT Group 4, JBIG is
  1100.     approximately 10% to 50% better on text and line art, and even
  1101.     better on halftones. JBIG is however, just like Group 4, somewhat
  1102.     sensitive to noise in images. This means that the compression ratio
  1103.     decreases when the amount of noise in your images increases.
  1104.  
  1105.   An example of an application would be browsing through an image
  1106.   database, e.g. an EDMS (engineering document management system).
  1107.   Large A0 size drawings at 300 dpi or so would be stored using five
  1108.   resolution layers. The lowest resolution layer would fit on a
  1109.   computer screen. Base layer compressed data would be stored at the
  1110.   beginning of the compressed file, thus making browsing through large
  1111.   numbers of compressed drawings possible by reading and decompressing
  1112.   just the first small part of all files. When the user stops browsing,
  1113.   the system could automatically start decompressing all remaining
  1114.   detail for printing at high resolution.
  1115.  
  1116.   [1] "Progressive Bi-level Image Compression, Revision 4.1", ISO/IEC
  1117.       JTC1/SC2/WG9, CD 11544, September 16, 1991
  1118.   [2] "An overview of the basic principles of the Q-coder adaptive
  1119.       binary arithmetic coder", W.B. Pennebaker, J.L. Mitchell, G.G.
  1120.       Langdon, R.B. Arps, IBM Journal of research and development,
  1121.       Vol.32, No.6, November 1988, pp. 771-726 (See also the other
  1122.       articles about the Q-coder in this issue)
  1123.  
  1124. ------------------------------------------------------------------------------
  1125.  
  1126. Subject: [75] Introduction to JPEG
  1127.  
  1128. Here is a brief overview of the inner workings of JPEG, plus some
  1129. references for more detailed information, written by Tom Lane
  1130. <tgl+@cs.cmu.edu>.  Please read item 19 in part 1 first.
  1131.  
  1132. JPEG works on either full-color or gray-scale images; it does not handle
  1133. bilevel (black and white) images, at least not efficiently.  It doesn't
  1134. handle colormapped images either; you have to pre-expand those into an
  1135. unmapped full-color representation.  JPEG works best on "continuous tone"
  1136. images; images with many sudden jumps in color values will not compress well.
  1137.  
  1138. There are a lot of parameters to the JPEG compression process.  By adjusting
  1139. the parameters, you can trade off compressed image size against reconstructed
  1140. image quality over a *very* wide range.  You can get image quality ranging
  1141. from op-art (at 100x smaller than the original 24-bit image) to quite
  1142. indistinguishable from the source (at about 3x smaller).  Usually the
  1143. threshold of visible difference from the source image is somewhere around 10x
  1144. to 20x smaller than the original, ie, 1 to 2 bits per pixel for color images.
  1145. Grayscale requires a little bit less space.
  1146.  
  1147. JPEG defines a "baseline" lossy algorithm, plus optional extensions for
  1148. progressive and hierarchical coding.  There is also a separate lossless
  1149. compression mode; this typically gives about 2:1 compression, ie about 12
  1150. bits per color pixel.  Most currently available JPEG hardware and software
  1151. handles only the baseline mode.
  1152.  
  1153.  
  1154. Here's the outline of the baseline compression algorithm:
  1155.  
  1156. 1. Transform the image into a suitable color space.  This is a no-op for
  1157. grayscale, but for color images you generally want to transform RGB into a
  1158. luminance/chrominance color space (YCbCr, YUV, etc).  The luminance component
  1159. is grayscale and the other two axes are color information.  The reason for
  1160. doing this is that you can afford to lose a lot more information in the
  1161. chrominance components than you can in the luminance component; the human eye
  1162. is not as sensitive to high-frequency color info as it is to high-frequency
  1163. luminance.  (See any TV system for precedents.)  You don't have to change the
  1164. color space if you don't want to, as the remainder of the algorithm works on
  1165. each color component independently, and doesn't care just what the data is.
  1166. However, compression will be less since you will have to code all the
  1167. components at luminance quality.
  1168.  
  1169. 2. (Optional) Downsample each component by averaging together groups of
  1170. pixels.  The luminance component is left at full resolution, while the color
  1171. components are usually reduced 2:1 horizontally and either 2:1 or 1:1 (no
  1172. change) vertically.  In JPEG-speak these alternatives are usually called
  1173. 2h2v and 2h1v sampling, but you may also see the terms "411" and "422"
  1174. sampling.  This step immediately reduces the data volume by one-half or
  1175. one-third, while having almost no impact on perceived quality.  (Obviously
  1176. this would not be true if you tried it in RGB color space...)  Note that
  1177. downsampling is not applicable to gray-scale data.
  1178.  
  1179. 3. Group the pixel values for each component into 8x8 blocks.  Transform each
  1180. 8x8 block through a discrete cosine transform (DCT); this is a relative of the
  1181. Fourier transform and likewise gives a frequency map, with 8x8 components.
  1182. Thus you now have numbers representing the average value in each block and
  1183. successively higher-frequency changes within the block.  The motivation for
  1184. doing this is that you can now throw away high-frequency information without
  1185. affecting low-frequency information.  (The DCT transform itself is reversible
  1186. except for roundoff error.)  See question 25 for fast DCT algorithms.
  1187.  
  1188. 4. In each block, divide each of the 64 frequency components by a separate
  1189. "quantization coefficient", and round the results to integers.  This is the
  1190. fundamental information-losing step.  A Q.C. of 1 loses no information;
  1191. larger Q.C.s lose successively more info.  The higher frequencies are normally
  1192. reduced much more than the lower.  (All 64 Q.C.s are parameters to the
  1193. compression process; tuning them for best results is a black art.  It seems
  1194. likely that the best values are yet to be discovered.  Most existing coders
  1195. use simple multiples of the example tables given in the JPEG standard.)
  1196.  
  1197. 5. Encode the reduced coefficients using either Huffman or arithmetic coding.
  1198. (Strictly speaking, baseline JPEG only allows Huffman coding; arithmetic
  1199. coding is an optional extension.)   Notice that this step is lossless, so it
  1200. doesn't affect image quality.  The arithmetic coding option uses Q-coding;
  1201. it is identical to the coder used in JBIG (see question 74).  Be aware that
  1202. Q-coding is patented.  Most existing implementations support only the Huffman
  1203. mode, so as to avoid license fees.  The arithmetic mode offers maybe 5 or 10%
  1204. better compression, which isn't enough to justify paying fees.
  1205.  
  1206. 6. Tack on appropriate headers, etc, and output the result.  In an
  1207. "interchange" JPEG file, all of the compression parameters are included
  1208. in the headers so that the decompressor can reverse the process.  For
  1209. specialized applications, the spec permits the parameters to be omitted
  1210. from the file; this saves several hundred bytes of overhead, but it means
  1211. that the decompressor must know what parameters the compressor used.
  1212.  
  1213.  
  1214. The decompression algorithm reverses this process, and typically adds some
  1215. smoothing steps to reduce pixel-to-pixel discontinuities.
  1216.  
  1217.  
  1218. Extensions:
  1219.  
  1220. The progressive mode is intended to support real-time transmission of images.
  1221. It allows the DCT coefficients to be sent incrementally in multiple "scans"
  1222. of the image.  With each scan, the decoder can produce a higher-quality
  1223. rendition of the image.  Thus a low-quality preview can be sent very quickly,
  1224. then refined as time allows.  Notice that the decoder must do essentially a
  1225. full JPEG decode cycle for each scan, so this scheme is useful only with fast
  1226. decoders (meaning dedicated hardware, at least at present).  However, the
  1227. total number of bits sent can actually be somewhat less than is necessary in
  1228. the baseline mode, especially if arithmetic coding is used.  So progressive
  1229. coding might be useful even if the decoder will simply save up the bits and
  1230. make only one output pass.
  1231.  
  1232. The hierarchical mode represents an image at multiple resolutions.  For
  1233. example, one could provide 512x512, 1024x1024, and 2048x2048 versions of the
  1234. image.  The higher-resolution images are coded as differences from the next
  1235. smaller image, and thus require many fewer bits than they would if stored
  1236. independently.  (However, the total number of bits will be greater than that
  1237. needed to store just the highest-resolution frame.)  Note that the individual
  1238. frames in a hierarchical sequence may be coded progressively if desired.
  1239.  
  1240.  
  1241. Lossless JPEG:
  1242.  
  1243. The separate lossless mode does not use DCT, since roundoff errors prevent a
  1244. DCT calculation from being lossless.  For the same reason, one would not
  1245. normally use colorspace conversion or downsampling, although these are
  1246. permitted by the standard.  The lossless mode simply codes the difference
  1247. between each pixel and the "predicted" value for the pixel.  The predicted
  1248. value is a simple function of the already-transmitted pixels just above and
  1249. to the left of the current one (eg, their average; 8 different predictor
  1250. functions are permitted).  The sequence of differences is encoded using the
  1251. same back end (Huffman or arithmetic) used in the lossy mode.
  1252.  
  1253. The main reason for providing a lossless option is that it makes a good
  1254. adjunct to the hierarchical mode: the final scan in a hierarchical sequence
  1255. can be a lossless coding of the remaining differences, to achieve overall
  1256. losslessness.  This isn't quite as useful as it may at first appear, because
  1257. exact losslessness is not guaranteed unless the encoder and decoder have
  1258. identical IDCT implementations (ie identical roundoff errors).
  1259.  
  1260.  
  1261. References:
  1262.  
  1263. For a good technical introduction to JPEG, see:
  1264.     Wallace, Gregory K.  "The JPEG Still Picture Compression Standard",
  1265.     Communications of the ACM, April 1991 (vol. 34 no. 4), pp. 30-44.
  1266. (Adjacent articles in that issue discuss MPEG motion picture compression,
  1267. applications of JPEG, and related topics.)  If you don't have the CACM issue
  1268. handy, a PostScript file containing a revised version of this article is
  1269. available at ftp.uu.net, graphics/jpeg/wallace.ps.Z.  The file (actually a
  1270. preprint for an article to appear in IEEE Trans. Consum. Elect.) omits the
  1271. sample images that appeared in CACM, but it includes corrections and some
  1272. added material.  Note: the Wallace article is copyright ACM and IEEE, and
  1273. it may not be used for commercial purposes.
  1274.  
  1275. An alternative, more leisurely explanation of JPEG can be found in "The Data
  1276. Compression Book" by Mark Nelson ([Nel 1991], see question 7).  This book
  1277. provides excellent introductions to many data compression methods including
  1278. JPEG, plus sample source code in C.  The JPEG-related source code is far from
  1279. industrial-strength, but it's a pretty good learning tool.
  1280.  
  1281. An excellent textbook about JPEG is "JPEG Still Image Data Compression
  1282. Standard" by William B. Pennebaker and Joan L. Mitchell.  Published by Van
  1283. Nostrand Reinhold, 1993, ISBN 0-442-01272-1.  650 pages, price US$59.95.
  1284. (VNR will accept credit card orders at 800/842-3636, or get your local
  1285. bookstore to order it.)  This book includes the complete text of the ISO
  1286. JPEG standards, DIS 10918-1 and draft DIS 10918-2.  Review by Tom Lane:
  1287. "This is by far the most complete exposition of JPEG in existence.  It's
  1288. written by two people who know what they are talking about: both serve on the
  1289. ISO JPEG standards committee.  If you want to know how JPEG works or why it
  1290. works that way, this is the book to have."
  1291.  
  1292. There are a number of errors in the first printing of the Pennebaker
  1293. & Mitchell book.  An errata list is available at ftp.uu.net:
  1294. graphics/jpeg/pm.errata.  At last report, all were fixed in the
  1295. second printing.
  1296.  
  1297. The official specification of JPEG is not currently available on-line.
  1298. I hear that CCITT specs may be on-line sometime soon, which would change this.
  1299. At the moment, your best bet is to buy the Pennebaker and Mitchell textbook.
  1300.  
  1301.  
  1302. ------------------------------------------------------------------------------
  1303.  
  1304. Subject: [76] What is Vector Quantization?
  1305.  
  1306. Some vector quantization software for data analysis that is available
  1307. from cochlea.hut.fi (130.233.168.48) in the /pub directory.  One
  1308. package is lvq_pak and one is som_pak (som_pak generates Kohonen maps
  1309. of data using lvq to cluster it).
  1310.  
  1311. For a book on Vector Quantization, see the reference (Gersho and Gray)
  1312. given in item 7 of this FAQ.
  1313.  
  1314. A short introduction to Vector Quantization, written by Alex Zatsman
  1315. <alex.zatsman@analog.com>:
  1316.  
  1317. In Scalar  Quantization one represents  the values by  fixed subset of
  1318. representative values. For  examples, if you  have  16 bit  values and
  1319. send  only 8 most  signifcant bits, you  get an  approximation  of the
  1320. original data  at  the expense of  precision.  In this case  the fixed
  1321. subset is all the 16-bit numbers divisable by 256, i.e 0, 256, 512,...
  1322.  
  1323. In  Vector Quantization  you   represent   not individual values   but
  1324. (usually small) arrays of them. A typical  example  is a color  map: a
  1325. color picture can  be  represented by  a  2D array  of  triplets  (RGB
  1326. values). In most pictures  those triplets do  not cover the  whole RGB
  1327. space but  tend to   concetrate  in certain   areas. For  example, the
  1328. picture of a forest will typically have a lot of green. One can select
  1329. a relatively  small  subset (typically 256 elements) of representative
  1330. colors, i.e RGB  triplets,  and then approximate  each  triplet by the
  1331. representative of  that small set. In case  of 256 one  can use 1 byte
  1332. instead of 3 for each pixel.
  1333.  
  1334. One  can do   the  same   for  any large  data  sets,  especialy  when
  1335. consecutive points are correlated in some way. CELP speech compression
  1336. algorithms  use  those subsets  "codebooks" and   use them to quantize
  1337. exciation vectors  for linear prediction  -- hence the name CELP which
  1338. stands for Codebook Excited Linear Prediction.  (See item 26 in part 1
  1339. of this FAQ for more information about CELP.)
  1340.  
  1341. Note that Vector Quantization, just like Scalar Quantization, is a lossy
  1342. compression.
  1343.  
  1344. ------------------------------------------------------------------------------
  1345.  
  1346. Subject: [77] Introduction to Fractal compression (long)
  1347.  
  1348.  
  1349. Written by John Kominek <jmkomine@jeeves.uwaterloo.ca>.
  1350.  
  1351. Seven things you should know about Fractal Image Compression (assuming that 
  1352. you want to know about it).
  1353.  
  1354.    1. It is a promising new technology, arguably superior to JPEG -- 
  1355.       but only with an argument.
  1356.    2. It is a lossy compression method.
  1357.    3. The fractals in Fractal Image Compression are Iterated Function
  1358.       Systems.
  1359.    4. It is a form of Vector Quantization, one that employs a virtual
  1360.       codebook.
  1361.    5. Resolution enhancement is a powerful feature but is not some
  1362.       magical way of achieving 1000:1 compression.
  1363.    6. Compression is slow, decompression is fast.
  1364.    7. The technology is patented.
  1365.  
  1366. That's the scoop in condensed form. Now to elaborate, beginning with a little 
  1367. background.
  1368.  
  1369.  
  1370.  A Brief History of Fractal Image Compression
  1371.  --------------------------------------------
  1372.  
  1373. The birth of fractal geometry (or rebirth, rather) is usually traced to IBM 
  1374. mathematician Benoit B. Mandelbrot and the 1977 publication of his seminal 
  1375. book The Fractal Geometry of Nature. The book put forth a powerful thesis: 
  1376. traditional geometry with its straight lines and smooth surfaces does not 
  1377. resemble the geometry of trees and clouds and mountains. Fractal geometry, 
  1378. with its convoluted coastlines and detail ad infinitum, does.
  1379.  
  1380. This insight opened vast possibilities. Computer scientists, for one, found a 
  1381. mathematics capable of generating artificial and yet realistic looking land-
  1382. scapes, and the trees that sprout from the soil. And mathematicians had at 
  1383. their disposal a new world of geometric entities.
  1384.  
  1385. It was not long before mathematicians asked if there was a unity among this 
  1386. diversity. There is, as John Hutchinson demonstrated in 1981, it is the branch 
  1387. of mathematics now known as Iterated Function Theory. Later in the decade 
  1388. Michael Barnsley, a leading researcher from Georgia Tech, wrote the popular 
  1389. book Fractals Everywhere. The book presents the mathematics of Iterated Func-
  1390. tions Systems (IFS), and proves a result known as the Collage Theorem. The 
  1391. Collage Theorem states what an Iterated Function System must be like in order 
  1392. to represent an image.
  1393.  
  1394. This presented an intriguing possibility. If, in the forward direction, frac-
  1395. tal mathematics is good for generating natural looking images, then, in the 
  1396. reverse direction, could it not serve to compress images? Going from a given 
  1397. image to an Iterated Function System that can generate the original (or at 
  1398. least closely resemble it), is known as the inverse problem. This problem 
  1399. remains unsolved.
  1400.  
  1401. Barnsley, however, armed with his Collage Theorem, thought he had it solved. 
  1402. He applied for and was granted a software patent and left academia to found 
  1403. Iterated Systems Incorporated (US patent 4,941,193. Alan Sloan is the co-
  1404. grantee of the patent and co-founder of Iterated Systems.)  Barnsley announced 
  1405. his success to the world in the January 1988 issue of BYTE magazine. This 
  1406. article did not address the inverse problem but it did exhibit several images 
  1407. purportedly compressed in excess of 10,000:1. Alas, it was not a breakthrough. 
  1408. The images were given suggestive names such as "Black Forest" and "Monterey 
  1409. Coast" and "Bolivian Girl" but they were all manually constructed. Barnsley's 
  1410. patent has come to be derisively referred to as the "graduate student algo-
  1411. rithm."
  1412.  
  1413. Graduate Student Algorithm
  1414.    o Acquire a graduate student.
  1415.    o Give the student a picture.
  1416.    o And a room with a graphics workstation.
  1417.    o Lock the door.
  1418.    o Wait until the student has reverse engineered the picture.
  1419.    o Open the door.
  1420.  
  1421. Attempts to automate this process have met little success. As Barnsley admit-
  1422. ted in 1988: "Complex color images require about 100 hours each to encode and 
  1423. 30 minutes to decode on the Masscomp [dual processor workstation]." That's 100 
  1424. hours with a _person_ guiding the process.
  1425.  
  1426. Ironically, it was one of Barnsley's PhD students that made the graduate 
  1427. student algorithm obsolete. In March 1988, according to Barnsley, he arrived 
  1428. at a modified scheme for representing images called Partitioned Iterated 
  1429. Function Systems (PIFS). Barnsley applied for and was granted a second patent 
  1430. on an algorithm that can automatically convert an image into a Partitioned 
  1431. Iterated Function System, compressing the image in the process. (US patent 
  1432. 5,065,447. Granted on Nov. 12 1991.) For his PhD thesis, Arnaud Jacquin imple-
  1433. mented the algorithm in software, a description of which appears in his land-
  1434. mark paper "Image Coding Based on a Fractal Theory of Iterated Contractive 
  1435. Image Transformations." The algorithm was not sophisticated, and not speedy, 
  1436. but it was fully automatic. This came at price: gone was the promise of 
  1437. 10,000:1 compression. A 24-bit color image could typically be compressed from 
  1438. 8:1 to 50:1 while still looking "pretty good." Nonetheless, all contemporary 
  1439. fractal image compression programs are based upon Jacquin's paper.
  1440.  
  1441. That is not to say there are many fractal compression programs available. 
  1442. There are not. Iterated Systems sell the only commercial compressor/decompres-
  1443. sor, an MS-Windows program called "Images Incorporated." There are also an 
  1444. increasing number of academic programs being made freely available. Unfor-
  1445. tunately, these programs are -- how should I put it? -- of merely academic 
  1446. quality. 
  1447.  
  1448. This scarcity has much to do with Iterated Systems' tight lipped policy about 
  1449. their compression technology. They do, however, sell a Windows DLL for pro-
  1450. grammers. In conjunction with independent development by researchers else-
  1451. where, therefore, fractal compression will gradually become more pervasive. 
  1452. Whether it becomes all-pervasive remains to be seen.
  1453.  
  1454. Historical Highlights:
  1455.    1977 -- Benoit Mandelbrot finishes the first edition of The Fractal 
  1456.            Geometry of Nature.
  1457.    1981 -- John Hutchinson publishes "Fractals and Self-Similarity."
  1458.    1983 -- Revised edition of The Fractal Geometry of Nature is 
  1459.            published.
  1460.    1985 -- Michael Barnsley and Stephen Demko introduce Iterated
  1461.            Function Theory in "Iterated Function Systems and the Global
  1462.            Construction of Fractals."
  1463.    1987 -- Iterated Systems Incorporated is founded.
  1464.    1988 -- Barnsley publishes the book Fractals Everywhere.
  1465.    1990 -- Barnsley's first patent is granted.
  1466.    1991 -- Barnsley's second patent is granted.
  1467.    1992 -- Arnaud Jacquin publishes an article that describes the first
  1468.            practical fractal image compression method.
  1469.    1993 -- The book Fractal Image Compression by Michael Barnsley and Lyman 
  1470.            Hurd is published.
  1471.         -- The Iterated Systems' product line matures. 
  1472.    1994 -- Put your name here.
  1473.  
  1474.  
  1475.  On the Inside
  1476.  -------------
  1477.  
  1478. The fractals that lurk within fractal image compression are not those of the 
  1479. complex plane (Mandelbrot Set, Julia sets), but of Iterated Function Theory. 
  1480. When lecturing to lay audiences, the mathematician Heinz-Otto Peitgen intro-
  1481. duces the notion of Iterated Function Systems with the alluring metaphor of a 
  1482. Multiple Reduction Copying Machine. A MRCM is imagined to be a regular copying 
  1483. machine except that:
  1484.  
  1485.   1. There are multiple lens arrangements to create multiple overlapping
  1486.      copies of the original.
  1487.   2. Each lens arrangement reduces the size of the original.
  1488.   3. The copier operates in a feedback loop, with the output of one
  1489.      stage the input to the next. The initial input may be anything.
  1490.  
  1491. The first point is what makes an IFS a system. The third is what makes it 
  1492. iterative. As for the second, it is implicitly understood that the functions 
  1493. of an Iterated Function Systems are contractive. 
  1494.  
  1495. An IFS, then, is a set of contractive transformations that map from a defined 
  1496. rectangle of the real plane to smaller portions of that rectangle. Almost 
  1497. invariably, affine transformations are used. Affine transformations act to 
  1498. translate, scale, shear, and rotate points in the plane. Here is a simple 
  1499. example:
  1500.  
  1501.  
  1502.      |---------------|              |-----|
  1503.      |x              |              |1    |
  1504.      |               |              |     |
  1505.      |               |         |---------------|
  1506.      |               |         |2      |3      |
  1507.      |               |         |       |       |
  1508.      |---------------|         |---------------|  
  1509.  
  1510.          Before                      After
  1511.  
  1512.      Figure 1. IFS for generating Sierpinski's Triangle.
  1513.  
  1514. This IFS contains three component transformations (three separate lens ar-
  1515. rangements in the MRCM metaphor). Each one shrinks the original by a factor of 
  1516. 2, and then translates the result to a new location. It may optionally scale 
  1517. and shift the luminance values of the rectangle, in a manner similar to the 
  1518. contrast and brightness knobs on a TV.
  1519.  
  1520. The amazing property of an IFS is that when the set is evaluated by iteration, 
  1521. (i.e. when the copy machine is run), a unique image emerges. This latent image 
  1522. is called the fixed point or attractor of the IFS. As guaranteed by a result 
  1523. known as the Contraction Theorem, it is completely independent of the initial 
  1524. image. Two famous examples are Sierpinski's Triangle and Barnsley's Fern. 
  1525. Because these IFSs are contractive, self-similar detail is created at every 
  1526. resolution down to the infinitesimal. That is why the images are fractal.
  1527.  
  1528. The promise of using fractals for image encoding rests on two suppositions: 1. 
  1529. many natural scenes possess this detail within detail structure (e.g. clouds), 
  1530. and 2. an IFS can be found that generates a close approximation of a scene 
  1531. using only a few transformations. Barnsley's fern, for example, needs but 
  1532. four. Because only a few numbers are required to describe each transformation, 
  1533. an image can be represented very compactly. Given an image to encode, finding 
  1534. the optimal IFS from all those possible is known as the inverse problem.
  1535.  
  1536. The inverse problem -- as mentioned above -- remains unsolved. Even if it 
  1537. were, it may be to no avail. Everyday scenes are very diverse in subject 
  1538. matter; on whole, they do not obey fractal geometry. Real ferns do not branch 
  1539. down to infinity. They are distorted, discolored, perforated and torn. And the 
  1540. ground on which they grow looks very much different.
  1541.  
  1542. To capture the diversity of real images, then, Partitioned IFSs are employed. 
  1543. In a PIFS, the transformations do not map from the whole image to the parts, 
  1544. but from larger parts to smaller parts. An image may vary qualitatively from 
  1545. one area to the next (e.g. clouds then sky then clouds again). A PIFS relates 
  1546. those areas of the original image that are similar in appearance. Using Jac-
  1547. quin's notation, the big areas are called domain blocks and the small areas 
  1548. are called range blocks. It is necessary that every pixel of the original 
  1549. image belong to (at least) one range block. The pattern of range blocks is 
  1550. called the partitioning of an image.
  1551.  
  1552. Because this system of mappings is still contractive, when iterated it will 
  1553. quickly converge to its latent fixed point image. Constructing a PIFS amounts 
  1554. to pairing each range block to the domain block that it most closely resembles 
  1555. under some to-be-determined affine transformation. Done properly, the PIFS 
  1556. encoding of an image will be much smaller than the original, while still 
  1557. resembling it closely.
  1558.  
  1559. Therefore, a fractal compressed image is an encoding that describes:
  1560.    1. The grid partitioning (the range blocks).
  1561.    2. The affine transforms (one per range block).
  1562.  
  1563. The decompression process begins with a flat gray background. Then the set of 
  1564. transformations is repeatedly applied. After about four iterations the attrac-
  1565. tor stabilizes. The result will not (usually) be an exact replica of the 
  1566. original, but reasonably close.
  1567.  
  1568.  
  1569.  Scalelessnes and Resolution Enhancement
  1570.  ---------------------------------------
  1571.  
  1572. When an image is captured by an acquisition device, such as a camera or scan-
  1573. ner, it acquires a scale determined by the sampling resolution of that device. 
  1574. If software is used to zoom in on the image, beyond a certain point you don't 
  1575. see additional detail, just bigger pixels. 
  1576.  
  1577. A fractal image is different. Because the affine transformations are spatially 
  1578. contractive, detail is created at finer and finer resolutions with each itera-
  1579. tion. In the limit, self-similar detail is created at all levels of resolu-
  1580. tion, down the infinitesimal. Because there is no level that 'bottoms out' 
  1581. fractal images are considered to be scaleless.
  1582.  
  1583. What this means in practice is that as you zoom in on a fractal image, it will 
  1584. still look 'as it should' without the staircase effect of pixel replication. 
  1585. The significance of this is cause of some misconception, so here is the right 
  1586. spot for a public service announcement.
  1587.  
  1588.                         /--- READER BEWARE ---\
  1589.  
  1590. Iterated Systems is fond of the following argument. Take a portrait that is, 
  1591. let us say, a grayscale image 250x250 pixels in size, 1 byte per pixel. You 
  1592. run it through their software and get a 2500 byte file (compression ratio = 
  1593. 25:1). Now zoom in on the person's hair at 4x magnification. What do you see? 
  1594. A texture that still looks like hair. Well then, it's as if you had an image 
  1595. 1000x1000 pixels in size. So your _effective_ compression ratio is 25x16=400.
  1596.  
  1597. But there is a catch. Detail has not been retained, but generated. With a 
  1598. little luck it will look as it should, but don't count on it. Zooming in on a 
  1599. person's face will not reveal the pores. 
  1600.  
  1601. Objectively, what fractal image compression offers is an advanced form of 
  1602. interpolation. This is a useful and attractive property. Useful to graphic 
  1603. artists, for example, or for printing on a high resolution device. But it does 
  1604. not bestow fantastically high compression ratios.
  1605.  
  1606.                         \--- READER BEWARE ---/
  1607.  
  1608. That said, what is resolution enhancement? It is the process of compressing an 
  1609. image, expanding it to a higher resolution, saving it, then discarding the 
  1610. iterated function system. In other words, the compressed fractal image is the 
  1611. means to an end, not the end itself.
  1612.  
  1613.  
  1614.  The Speed Problem
  1615.  -----------------
  1616.  
  1617. The essence of the compression process is the pairing of each range block to a 
  1618. domain block such that the difference between the two, under an affine trans-
  1619. formation, is minimal. This involves a lot of searching. 
  1620.  
  1621. In fact, there is nothing that says the blocks have to be squares or even 
  1622. rectangles. That is just an imposition made to keep the problem tractable. 
  1623.  
  1624. More generally, the method of finding a good PIFS for any given image involves 
  1625. five main issues: 
  1626.    1. Partitioning the image into range blocks. 
  1627.    2. Forming the set of domain blocks. 
  1628.    3. Choosing type of transformations that will be considered. 
  1629.    4. Selecting a distance metric between blocks. 
  1630.    5. Specifying a method for pairing range blocks to domain blocks. 
  1631.  
  1632. Many possibilities exist for each of these. The choices that Jacquin offered 
  1633. in his paper are: 
  1634.    1. A two-level regular square grid with 8x8 pixels for the large
  1635.       range blocks and 4x4 for the small ones. 
  1636.    2. Domain blocks are 16x16 and 8x8 pixels in size with a subsampling 
  1637.       step size of four. The 8 isometric symmetries (four rotations, 
  1638.       four mirror flips) expand the domain pool to a virtual domain 
  1639.       pool eight times larger. 
  1640.    3. The choices in the last point imply a shrinkage by two in each 
  1641.       direction, with a possible rotation or flip, and then a trans-
  1642.       lation in the image plane. 
  1643.    4. Mean squared error is used. 
  1644.    5. The blocks are categorized as of type smooth, midrange, simple
  1645.       edge, and complex edge. For a given range block the respective
  1646.       category is searched for the best match.
  1647.  
  1648. The importance of categorization can be seen by calculating the size of the 
  1649. total domain pool. Suppose the image is partitioned into 4x4 range blocks. A 
  1650. 256x256 image contains a total of (256-8+1)^2  = 62,001 different 8x8 domain 
  1651. blocks. Including the 8 isometric symmetries increases this total to 496,008. 
  1652. There are (256-4+1)^2 = 64,009 4x4 range blocks, which makes for a maximum of 
  1653. 31,748,976,072 possible pairings to test. Even on a fast workstation an ex-
  1654. haustive search is prohibitively slow. You can start the program before de-
  1655. parting work Friday afternoon; Monday morning, it will still be churning away. 
  1656.  
  1657. Increasing the search speed is the main challenge facing fractal image com-
  1658. pression.
  1659.  
  1660.  
  1661.  Similarity to Vector Quantization
  1662.  ---------------------------------
  1663.  
  1664. To the VQ community, a "vector" is a small rectangular block of pixels. The 
  1665. premise of vector quantization is that some patterns occur much more frequent-
  1666. ly than others. So the clever idea is to store only a few of these common 
  1667. patterns in a separate file called the codebook. Some codebook vectors are 
  1668. flat, some are sloping, some contain tight texture, some sharp edges, and so 
  1669. on -- there is a whole corpus on how to construct a codebook. Each codebook 
  1670. entry (each domain block) is assigned an index number. A given image, then, is 
  1671. partitioned into a regular grid array. Each grid element (each range block) is 
  1672. represented by an index into the codebook. Decompressing a VQ file involves 
  1673. assembling an image out of the codebook entries. Brick by brick, so to speak.
  1674.  
  1675. The similarity to fractal image compression is apparent, with some notable 
  1676. differences. 
  1677.    1. In VQ the range blocks and domain blocks are the same size; in an
  1678.       IFS the domain blocks are always larger. 
  1679.    2. In VQ the domain blocks are copied straight; in an IFS each domain 
  1680.       block undergoes a luminance scaling and offset.
  1681.    3. In VQ the codebook is stored apart from the image being coded; in 
  1682.       an IFS the codebook is not explicitly stored. It is comprised of
  1683.       portions of the attractor as it emerges during iteration. For that
  1684.       reason it is called a "virtual codebook." It has no existence
  1685.       independent of the affine transformations that define an IFS.
  1686.    4. In VQ the codebook is shared among many images; in an IFS the 
  1687.       virtual codebook is specific to each image.
  1688.  
  1689. There is a more refined version of VQ called gain-shape vector quantization in 
  1690. which a luminance scaling and offset is also allowed. This makes the similari-
  1691. ty to fractal image compression as close as can be.
  1692.  
  1693.  
  1694.  Compression Ratios
  1695.  ------------------
  1696.  
  1697. Exaggerated claims not withstanding, compression ratios typically range from 
  1698. 4:1 to 100:1. All other things equal, color images can be compressed to a 
  1699. greater extent than grayscale images.
  1700.  
  1701. The size of a fractal image file is largely determined by the number of trans-
  1702. formations of the PIFS. For the sake of simplicity, and for the sake of com-
  1703. parison to JPEG, assume that a 256x256x8 image is partitioned into a regular 
  1704. partitioning of 8x8 blocks. There are 1024 range blocks and thus 1024 trans-
  1705. formations to store. How many bits are required for each?
  1706.  
  1707. In most implementations the domain blocks are twice the size of the range 
  1708. blocks. So the spatial contraction is constant and can be hard coded into the 
  1709. decompression program. What needs to be stored are:
  1710.  
  1711.    x position of domain block        8     6
  1712.    y position of domain block        8     6
  1713.    luminance scaling                 8     5
  1714.    luminance offset                  8     6
  1715.    symmetry indicator                3     3
  1716.                                     --    --
  1717.                                     35    26 bits
  1718.  
  1719. In the first scheme, a byte is allocated to each number except for the symme-
  1720. try indicator. The upper bound on the compression ratio is thus (8x8x8)/35 = 
  1721. 14.63. In the second scheme, domain blocks are restricted to coordinates 
  1722. modulo 4. Plus, experiments have revealed that 5 bits per scale factor and 6 
  1723. bits per offset still give good visual results. So the compression ratio limit 
  1724. is now 19.69. Respectable but not outstanding.
  1725.  
  1726. There are other, more complicated, schemes to reduce the bit rate further. The 
  1727. most common is to use a three or four level quadtree structure for the range 
  1728. partitioning. That way, smooth areas can be represented with large range 
  1729. blocks (high compression), while smaller blocks are used as necessary to 
  1730. capture the details. In addition, entropy coding can be applied as a back-end 
  1731. step to gain an extra 20% or so.
  1732.  
  1733.  
  1734.  Quality: Fractal vs. JPEG
  1735.  -------------------------
  1736.  
  1737. The greatest irony of the coding community is that great pains are taken to 
  1738. precisely measure and quantify the error present in a compressed image, and 
  1739. great effort is expended toward minimizing an error measure that most often is 
  1740. -- let us be gentle -- of dubious value. These measure include signal-to-noise 
  1741. ratio, root mean square error, and mean absolute error. A simple example is 
  1742. systematic shift: add a value of 10 to every pixel. Standard error measures 
  1743. indicate a large distortion, but the image has merely been brightened.
  1744.  
  1745. With respect to those dubious error measures, and at the risk of over-sim-
  1746. plification, the results of tests reveal the following: for low compression 
  1747. ratios JPEG is better, for high compression ratios fractal encoding is better. 
  1748. The crossover point varies but is often around 40:1. This figure bodes well 
  1749. for JPEG since beyond the crossover point images are so severely distorted 
  1750. that they are seldom worth using. 
  1751.  
  1752. Proponents of fractal compression counter that signal-to-noise is not a good 
  1753. error measure and that the distortions present are much more 'natural looking' 
  1754. than the blockiness of JPEG, at both low and high bit rates. This is a valid 
  1755. point but is by no means universally accepted. 
  1756.  
  1757. What the coding community desperately needs is an easy to compute error meas-
  1758. ure that accurately captures subjective impression of human viewers. Until 
  1759. then, your eyes are the best judge.
  1760.  
  1761.  
  1762.  Finding Out More
  1763.  ----------------
  1764.  
  1765.  Please refer to item 17 in part 1 of this FAQ for a list of references,
  1766. available software, and ftp sites.
  1767.  
  1768.  
  1769.           End of part 2 of the comp.compression faq.
  1770.  
  1771.